1.lexer understand codes of a programme and lexer uses pattern to generate token
now pattern are expressed by regular expression ir L(L+D)* for recognizing keywords .
2.we use grammars to define syntax of a programme how lets see
a + b * c this is our expression in one c programme
now related cfg is
E → E + T | T
T → T * F | F
F → (E) | id
now with this grammar help we generate syntax tree or called derivation tree
so grammars are well knows for synatx tree
remember syntax tree are also one form of intermeditate code which is source language depenedent machine code
and obviously we use PDA to accept CFG
3.code optimization has basically two parts
data flow analysis and control flow analysis
data flow analysis does what-its concerned with how data flows and this analysis helps us to
subparts of data flow analysis is
Live Variable Analysis
for register allocation and dead code elimination
Available Expressions Analysis
common subexpression elimination and copy propogation
Constant Propagation Analysis
note:
Register allocation is also part of optimization i dont know how it helps in code generation